package com.file;

import java.io.*;
/**
 * @Description: 字节流文件复制
 */
public class ByteFileCopy {
        public static void main(String[] args) throws IOException {
            String srcPath = "f:/test/testRead.txt";
            String destPath = "f:/test/testWrite.txt";
            copyFile(srcPath, destPath);
        }

        /**
         * @Description: 字节流文件复制
         * @Param:
         * @return:
         */
        public static void copyFile(String srcPath, String destPath) {
            // 打开输入流，输出流
            FileInputStream fis = null;
            BufferedInputStream bis = null;
            BufferedOutputStream bos = null;
            try {
                fis = new FileInputStream(srcPath);
                FileOutputStream fos = new FileOutputStream(destPath);

                // 使用缓冲流
                bis = new BufferedInputStream(fis);
                bos = new BufferedOutputStream(fos);
                // 读取和写入信息
                int len = 0;
                while ((len = bis.read()) != -1) {
                    bos.write(len);
                }
                bos.flush();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                // 关闭流
                try {
                    bis.close();
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }


        }

}
